﻿using Microsoft.Extensions.DependencyInjection;
using Modules.Cms.Entitys;
using Modules.Cms.Repositories;
using Modules.Corp.Repositories;
using Modules.Corp;
using PmSoft;
using PmSoft.ApplicationContext;
using Modules.System.Role;

namespace Modules.Cms;

[UseDI(ServiceLifetime.Scoped)]
public class CmsDealerService
{
    private readonly IApplicationContext applicationContext;
    private readonly CmsDealerRepository cmsDealerRepository;

    public CmsDealerService(IApplicationContext applicationContext, CmsDealerRepository cmsDealerRepository)
    {
        this.applicationContext = applicationContext;
        this.cmsDealerRepository = cmsDealerRepository;
    }

    public IPagedList<CmsDealer> GetPages(CmsDealerQuery query, int pageIndex, int pageSize)
    {
        return cmsDealerRepository.GetCmsDealers(query, pageIndex, pageSize);
    }

    public void Create(CmsDealer entity)
    {
        cmsDealerRepository.Insert(entity);
    }

    public void Update(CmsDealer entity)
    {
        cmsDealerRepository.Update(entity);
    }

    public void Delete(int id)
    {
        cmsDealerRepository.DeleteByEntityId(id);
    }

    public CmsDealer? Get(int id)
    {
        return cmsDealerRepository.Get(id);
    }

    public CmsDealer? GetDalerByUserId(int userId)
    {
        return cmsDealerRepository.GetDalerByUserId(userId);
    }
}
